package com.rr.jvm.javap;

/**
 * @author RR
 * @date 2022/9/8 20:46
 */
/*
* javac StringTableTest.java
* javap -v StringTableTest
* */
public class StringTableTest {
    public static void main(String[] args) {
        String s1 = "a";
        String s2 = "b";
        String s3 = "ab";
        String s4 = s1 + s2; // 底层是用StringBuilder拼接出新字符串
        String s5 = "a" + "b"; // 编译期就会把它变成ab，ab又在StringTable中出现过，所以s3和s5相等
        String s6 = s5.intern(); // intern()方法会 尝试 把字符串放到StringTable中，并返回StringTable中此变量的地址引用
        System.out.println(s3 == s4); // false
        System.out.println(s3 == s5); // true
        System.out.println(s3 == s6); // true
    }
}
